/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"04165277-801A-421D-A7A5-D324620E4D84",variableType:4}
 */
var fGrupoDestino = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C5070197-163B-420D-BA03-66B1ABECBF4E",variableType:4}
 */
var fGrupoFuente = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"32FE14BE-66CC-4D56-8709-36D65144BD18",variableType:4}
 */
var fSolucionDestino = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"770A0966-4B29-4451-977B-E76BE096B9CF",variableType:4}
 */
var fSolucionFuente = null;


/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DEA9821E-1384-4F66-B658-F2BA329AE2D5"}
 */
function copiar(event) {
	databaseManager.setAutoSave(false)
	var $fs = databaseManager.getFoundSet('fwk_navigation_infocom','pantallas')
	
	var $sql 	= 'SELECT * FROM pantallas WHERE id_solucion = ? AND nrogrupotree = ?'
	var $args 	= [fSolucionFuente, fGrupoFuente]
	var $ds 	= databaseManager.getDataSetByQuery('fwk_navigation_infocom',$sql,$args,-1)
	
	var $cant 	= $ds.getMaxRowIndex()
	var $cant_c = $ds.getMaxColumnIndex()
	
	for (var i = 1 ; i <= $cant ; i++)
	{
		$fs.newRecord()
		for (var j = 1 ; j <= $cant_c ; j++)
		{
			var $col = $ds.getColumnName(j)
			if ($col == 'id_solucion')
			{
				$fs.id_solucion = fSolucionDestino
			}
			else
			{
				if ($col == 'nrogrupotree')
				{
					$fs.nrogrupotree = fGrupoDestino
				}
				else
				{
					$fs[$col] = $ds.getValue(i,j)
				}
			}
		}
	}
	databaseManager.startTransaction()
	if (databaseManager.saveData())
	{
		if (databaseManager.commitTransaction())
		{
			databaseManager.setAutoSave(true)
			globals.DIALOGS.showInfoDialog('Aviso','Proceso terminado con éxito','OK')
			return
		}
		else
		{
			databaseManager.rollbackTransaction()
			databaseManager.revertEditedRecords()
			databaseManager.setAutoSave(true)
			globals.DIALOGS.showWarningDialog('Aviso','Error al intentar grabar los datos','OK')
		}
	}
	else
	{
		databaseManager.rollbackTransaction()
		databaseManager.revertEditedRecords()
		databaseManager.setAutoSave(true)
		globals.DIALOGS.showWarningDialog('Aviso','Ha ocurrido un error en los datos','OK')
	}
}

/**
 * Handle focus gained event of the element.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"68F11A02-DA19-4F9B-AEA8-85AF5F4F7D66"}
 */
function onFocusGainedGrupoFuente(event) {
	var $sql = 'SELECT descripcion, nrogrupo FROM grupostree WHERE solucion = ?'
	var $args = [fSolucionFuente]
	var $ds = databaseManager.getDataSetByQuery('fwk_navigation_infocom',$sql,$args,-1)
	application.setValueListItems('grupos_manual',$ds)
}

/**
 * Handle focus gained event of the element.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"427D96E0-6036-438B-B922-83EEDCDC6597"}
 */
function onFocusGainedGrupoDestino(event) {
	var $sql = 'SELECT descripcion, nrogrupo FROM grupostree WHERE solucion = ?'
	var $args = [fSolucionDestino]
	var $ds = databaseManager.getDataSetByQuery('fwk_navigation_infocom',$sql,$args,-1)
	application.setValueListItems('grupos_manual',$ds)
}
